﻿//策略模式实际应用案例
function querstionCreator(spec, my) {
    var that = {},
          my = my || {};
    my.label = spec.label;
    my.renderInput = function () {
        throw "not implemented";
    };
    that.render = function (target) {

    };
    return that;
}

function choiceQuestionCreator(spec) {
    var my = {},
          that = querstionCreator(spec, my);
    my.renderInput = function () {

    };
    return that;
}

function inputQuestionCreator(spec) {
    var my = {},
      that = querstionCreator(spec, my);
    my.renderInput = function () {

    };
    return that;
}

var view = {
    render: function (target, questions) {
        for (var i = 0, len = questions.length; i < len; i++) {
            target.appendChild(questions[i].render());
        }
    }
};

var questions = [
    choiceQuestionCreator({ label: '', choices: ['Yes', 'No'] }),
    inputQuestionCreator({ label: '' })
];
var questionRegion = document.getElementById('questions');
view.render(questionRegion, questions);